﻿using AutoMapper;
using B.S.Filtration.Domain;
using B.S.Filtration.ErrorCode;
using B.S.Filtration.Read.Api.Application.Command.AbnormalCommand;
using MediatR;
using SqlSugar;

namespace B.S.Filtration.Read.Api.Application.CommandHander.AbnormalHandler
{
    public class FTAbnormalHandler:IRequestHandler<FTAbnormalCommand,APIResult<List<Abnormal>>>
    {
        private readonly IMapper mapper;
        private readonly ISqlSugarClient db;

        public FTAbnormalHandler(IMapper mapper, ISqlSugarClient db)
        {
            this.mapper = mapper;
            this.db = db;
        }

        public async Task<APIResult<List<Abnormal>>> Handle(FTAbnormalCommand request, CancellationToken cancellationToken)
        {
            APIResult<List<Abnormal>> result = new APIResult<List<Abnormal>>();
            var list = await db.Queryable<Abnormal>().Where(x => x.IsDel == false && x.id == request.id).ToListAsync();
            result.data = list;
            result.code = APIResultCode.success;
            result.msg = "工序列表显示成功";
            return await Task.FromResult(result);
        }
    }
}
